package rladidxo.basic;

public class Ch04_235_02 {
public static void main(String[] args) {
	Rectangle r = new Rectangle();
	Rectangle s = new Rectangle(1,1,2,3);
	
	r.show();
	s.show();
	System.out.println("기준값 s는 "+s.square());
	r.set(-2,2,-1,4);
	s.show();
	r.show();
	
	System.out.println("입력값 r의 넓이는"+r.square()+"\t");
	
	if(r.equals(s)){
		System.out.println("두 사각형은 같습니다.");
	}else{System.out.println("두 사각형은 다릅니다.");}

}//main
}//class

class Rectangle{
	int x1;
	int y1;
	int x2;
	int y2;
	int high;
	int low;
	int width;
	int w2;
	int compare;
	int compare2;
	int arrange;
	
	
	
	public Rectangle() {high=0;width=0;}
	public Rectangle(int x1, int y1, int x2, int y2) {
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
		
	}
	void set(int x1, int y1, int x2, int y2){
		if(x1<0){x1=-(x1);}
		if(x2<0){x2=-(x2);}
		if(y1<0){y1=-(y1);}
		if(y2<0){y2=-(y2);}
		
		if(y1<y2){
			high = y2; low =y1;compare2 = y2-y1;
		}else{high = y1; low = y2;compare2 = y1-y2;}
		if(x1<x2){
			width = x2; w2=x1;compare = x2-x1;
		}else{width = x1; w2 =x2;compare = x1-x2;}
	}
	int square(){
		arrange= (high-low)*(width-w2);
		return arrange;
	}
	void show(){
		System.out.println("첫번째 점은"+x1+","+y1+" 두번째 점은 "+x2+","+y2+"입니다.");
		System.out.println("해당 점으로 이뤄진 사각형의 넓이는 "+arrange+"입니다.");
		if(x1<x2){
		if(x1-x2==y1-y2){System.out.println("해당 사각형은 정사각형입니다.");}
		else {System.out.println("해당 사각형은 직사각형입니다.");}}
		else if(x1==x2){System.out.println("해당 사각형은 정사각형입니다.");}
		else {System.out.println("해당 사각형은 직사각형입니다.");}
		System.out.println("---------------------------------");
		
	}
	boolean equals(Rectangle a){
		if(a.x1-a.x2==this.x1-this.x2){if(a.y1-a.y2==this.y1-this.y2){return true;}}
		else if(a.x2-a.x1==this.x2-this.x1){if(a.y2-a.y1==this.y2-this.y1){return true;}}
		else{return false;}
		return false;
	}
	}
	
